package com.fand.manager.controller;


import javax.annotation.Resource;

import com.fand.common.util.ResultHelp;
import com.fand.manager.model.userrole.SysUserRolePostDTO;
import com.fand.manager.model.userrole.SysUserRoleReturnDTO;
import com.fand.manager.service.ISysUserRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import io.swagger.annotations.Api;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户角色表 前端控制器
 * </p>
 *
 * @author javaboy
 * @since 2021-06-07
 */
@Api(tags = "用户角色表")
@RestController
@RequestMapping("/sys-user-role")
public class SysUserRoleController {

    @Resource
    private ISysUserRoleService sysUserRoleService;

    @ApiOperation("查询当前用户已分配和未分配角色")
    @PreAuthorize("hasAuthority('sys:user:role')")
    @GetMapping("/getRoleAndNRole")
    public ResultHelp<SysUserRoleReturnDTO> getRoleAndNRoleById(@RequestParam Long id){
        return ResultHelp.success(sysUserRoleService.getRoleAndNRole(id));
    }

    @ApiOperation("查询当前用户已分配和未分配角色")
    @PreAuthorize("hasAuthority('sys:user:role')")
    @PostMapping("/save")
    public ResultHelp<Boolean> saveUserRole(@RequestBody SysUserRolePostDTO sysUserRolePostDTO){
        return ResultHelp.success(sysUserRoleService.saveUserRole(sysUserRolePostDTO));
    }

}

